﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KBVault.Web.Infrastructure;
using KBVault.DAL.Entities;
using KBVault.DAL.Repository;

namespace KBVault.Web.Public
{
    public partial class ShowCategory : KBVaultPublicPage
    {
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!Page.IsPostBack)
            {
                if (ActiveCategoryId < 1)
                {
                    Response.Redirect("/Default.aspx");
                    return;
                }
                Category c = CategoryRepository.Get(ActiveCategoryId);
                categoryTitle.Text = c.Name;
                rptArticles.DataSource = c.Articles.Where(a => a.IsDraft == 0 && DateTime.Now.Date <= a.PublishEndDate && DateTime.Now.Date >= a.PublishStartDate);
                rptArticles.DataBind();
                linkEdit.Visible = IsAuthorized;
                linkNewArticle.Visible = IsAuthorized;
                linkEdit.NavigateUrl = String.Format("/Application/Categoryops.aspx?Op=edit&Category={0}&{1}", c.Id, ReturnUrlParameter);
                linkNewArticle.NavigateUrl = String.Format("/Application/ArticleOps.aspx?Op=new&Category={0}&{1}", c.Id, ReturnUrlParameter);
                SetPageTitle(c.Name);
            }
        }
    }
}